---
title: stats.Histogram
api: stats.Histogram
---

## Description

<Summary/>

_Histogram_ is one of a few types of metrics supported by the _stats_ system. It keeps track of observations in an array of buckets, and can be used to calculate quantiles. Once you've created one, it becomes visible to the _stats_ system, and its current value can be queried via admin port under the endpoint `GET /metrics` in [_Prometheus exposition formats_](https://prometheus.io/docs/instrumenting/exposition_formats/).

You create a _Histogram_ by a name and a series of bucket upper bounds, optionally providing label names if it has sub-metrics.

``` js
pipy({
  _lantency: new stats.Histogram(
    'http_requests',
    new Array(16).fill(0).map((_, i) => Math.pow(2, i)),
    ['service'],
  )
})
```

> Metric names starting with `pipy_` are reserved for internal use.

After that, you collect observations by [observe()](/reference/api/stats/Histogram/observe).

``` js
_lantency.observe(2.6)
```

You can also access a sub-metric by giving values to the labels. The label values must be given in the order they appear in the construction.

``` js
_lantency.withLabels('login-service').observe(3)
```

## Constructor

<Constructor/>

## Methods

<Methods/>

## See Also

* [stats](/reference/api/stats)
